import json

from api.base_service import BaseService


# 会员服务


class MemberServiceApi(BaseService):
    # 创建服务名实例属性
    def __init__(self):
        super().__init__()
        self.service = "MemberService"

    # 根据手机号查询会员信息
    def find_by_telephone(self, string_phone):
        resp = self.client.invoke(self.service, "findByTelephone", string_phone)
        if resp == 'null' or resp == 'Failed':
            return None
        else:
            return json.loads(resp)

    # 添加会员
    def add(self, dict_data):
        dict_data['class'] = 'com.itheima.pojo.Member'
        resp = self.client.invoke(self.service, "add", dict_data)
        if resp == 'null':
            return True
        else:
            return False

    # 根据日期统计会员数
    def find_member_count_by_months(self, list_string):
        resp = self.client.invoke(self.service, "findMemberCountByMonths", list_string)
        if resp == 'No' or resp == 'Failed':
            return None
        else:
            return json.loads(resp)


if __name__ == '__main__':

    ms = MemberServiceApi()
    # resp = ms.find_by_telephone(13020210001)
    # print('响应结果', type(resp), resp)
    resp=ms.add({"id": 7234, "name": "嗯", "phoneNumber": '13877655476'})
    print(type(resp),resp)
